package cc.booku.owlbox.Statistics;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListAdapter;
import android.widget.TextView;


import java.util.ArrayList;

import cc.booku.owlbox.R;

public class chartListAdapter extends BaseAdapter implements ListAdapter {


    private ArrayList<chart_list_class> chart_list_classList;
    private int id;
    private Context context;
    private LayoutInflater inflater;

    public chartListAdapter(int sub_item, Context context, ArrayList<chart_list_class> chart_list_classList) {
        this.chart_list_classList = chart_list_classList;
        this.context = context;
        this.id = sub_item;
        inflater = LayoutInflater.from(context);

    }

    @Override
    public int getCount() {
        return chart_list_classList.size();
    }

    @Override
    public Object getItem(int i) {
        return chart_list_classList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @SuppressLint("WrongConstant")
    @Override

    public View getView(int i, View view, ViewGroup viewGroup) {

        TextView num = null;
        TextView statistics_devicebrand = null;
        TextView count = null;
        ViewHolder viewHolder;
        if (view == null) {
            view = inflater.inflate(id, null);
            num = (TextView) view.findViewById(R.id.num);
            statistics_devicebrand = (TextView) view.findViewById(R.id.statistics_devicebrand);
            count = (TextView) view.findViewById(R.id.count);
            view.setTag(new ViewHolder(num, statistics_devicebrand, count));
        } else {
            ViewHolder viewHolder1 = (ViewHolder) view.getTag(); // 重新获取ViewHolder
            statistics_devicebrand = viewHolder1.statistics_devicebrand;
            num = viewHolder1.num;
            count = viewHolder1.count;
        }
        chart_list_class chart_list_classc = (chart_list_class) chart_list_classList.get(i); // 获取当前项的实例

        count.setText(chart_list_classc.getCount().toString());//对象为空
        num.setText(chart_list_classc.getNum().toString());
        statistics_devicebrand.setText(chart_list_classc.getStatistics_devicebrand().toString());

        return view;

    }


    private final class ViewHolder {
        TextView num = null;
        TextView statistics_devicebrand = null;
        TextView count = null;


        public ViewHolder(TextView num, TextView statistics_devicebrand, TextView count) {
            this.num = num;
            this.statistics_devicebrand = statistics_devicebrand;
            this.count = count;

        }

    }

}
